/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.me.cine25;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import java.util.LinkedList;

/**
 *
 * @author Jesus
 */
public class MainActivity extends Activity {

    private LinkedList<Pelicula> lista = new LinkedList<Pelicula>();
    private int[] myImageIds = {
        R.drawable.foto1,
        R.drawable.foto2,
        R.drawable.foto3,
        R.drawable.foto5
    };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {

        super.onCreate(icicle);
        setContentView(R.layout.principal);
        cargarUltimasPeliculas();
        //Toast.makeText(getBaseContext(), this.lista.size(), Toast.LENGTH_SHORT).show();
        ((Gallery) findViewById(R.id.gallery1)).setAdapter(new ImageAdapter(this, lista, 0));
        //((Gallery) findViewById(R.id.gallery)).setAdapter(new ImageAdapter(this, lista, 1));
        ((Gallery) findViewById(R.id.gallery)).setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                Toast.makeText(getBaseContext(), arg2, Toast.LENGTH_SHORT).show();
            }
        });
        ((Gallery) findViewById(R.id.gallery1)).setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                Toast.makeText(getBaseContext(), arg2, Toast.LENGTH_SHORT).show();
            }
        });

    }

    private void cargarUltimasPeliculas() {
        for (int i = 0; i < myImageIds.length; i++) {
        }
        /*String titulo,String director,String fecha_produccion,String guionista,String genero,String fecha_estreno,String productora,String fotografia,BSO banda_sonora,
        LinkedList<String> etiquetas ,int nota,Bitmap imagen*/
        LinkedList<String> etiquetas = new LinkedList<String>();
        etiquetas.add("dasfasd");
        Pelicula p = new Pelicula("Territorio prohibido dfdfdf", "Christopher Nolan", "16-04-1989", "Rodrigo testillano", "Accion,Drama", "25-04-1990", "Paramount", "Sergio Garcia", new BSO("Roberto Manzano"), etiquetas, 4.5, BitmapFactory.decodeResource(getResources(), myImageIds[0]), "safsadf");
        Toast.makeText(getBaseContext(), p.getDirector(), Toast.LENGTH_SHORT).show();

        this.lista.add(p);

        //Toast.makeText(getBaseContext(), this.lista.size(), Toast.LENGTH_SHORT).show();
        //lista.add(new Pelicula("Territorio prohibido dfdfdf","Christopher Nolan","16-04-1989","Rodrigo testillano","Accion,Drama","25-04-1990","Paramount","Sergio Garcia",new BSO("Roberto Manzano"),etiquetas,4.5,BitmapFactory.decodeResource(getResources(), myImageIds[1]),"sadfasdf"));
        //lista.add(new Pelicula("Territorio prohibido dfdfdf","Christopher Nolan","16-04-1989","Rodrigo testillano","Accion,Drama","25-04-1990","Paramount","Sergio Garcia",new BSO("Roberto Manzano"),etiquetas,4.5,BitmapFactory.decodeResource(getResources(), myImageIds[2]),"sdafasdf"));
        //lista.add(new Pelicula("Territorio prohibido dfdfdf","Christopher Nolan","16-04-1989","Rodrigo testillano","Accion,Drama","25-04-1990","Paramount","Sergio Garcia",new BSO("Roberto Manzano"),etiquetas,4.5,BitmapFactory.decodeResource(getResources(), myImageIds[3]),"dsafsadf"));

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {


        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_vista_principal, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection

        switch (item.getItemId()) {

            case R.id.Top25:
                Toast.makeText(this, WIFI_SERVICE, Toast.LENGTH_LONG).show();

                startActivity(new Intent(MainActivity.this, Top25.class));
                return true;

            default:
                return super.onOptionsItemSelected(item);
        }

    }
}
